/**
 * @fileOverview 
 * Contains JS code used by the demo.
 * @author Igor Kulkin <igor.kulkin@gmail.com>
 */

 
var editor = null;


function initialize() {
  editor = new PolygonEditor(document.getElementById('canvas'));
  editor.initialize();
  //editor.release();
  document.getElementById('undo').onclick = function() {
    if (!editor.undo()) alert('Already at the bottom of the stack.');
  };
  document.getElementById('redo').onclick = function() {
    if (!editor.redo()) alert('Already at the top of the stack.');
  };
  document.getElementById('simplify').onclick = function() {
    var newPolygon = geoPolygonUtils.simplifyPolygon(editor.getPolygon(), 50);
    if (newPolygon) {
      editor.updatePolygon(newPolygon);
    }
  };
  document.getElementById('correct').onclick = function() {
    var newPolygon = geoPolygonUtils.correctAngles(
        editor.getPolygon(), Math.PI * 0.5, Math.PI * 0.05);
    if (newPolygon) {
      editor.updatePolygon(newPolygon);
    }
  };
};


dojo.addOnLoad(initialize);